#!/bin/bash
. ./var
. ./Tmpdir
trash(){
    #调用Tmpdir函数
    Tmpdir
    cd $dir && wget -V &> /dev/null || yum -y install wget
    /usr/local/bin/trash --version &> /dev/null && echoRed "检测到系统中有trash命令，故而退出！" && rm -rf $dir && exit 1
    which trash
    if [ $? = 0 ];then
        echoRed "系统存在trash命令，请检查，即将退出"
        rm -rf $dir && exit 6
    else
        echoYellow "系统中未存在trash命令，即将安装"
    fi

    #wget https://github.com/andreafrancia/trash-cli/archive/master.zip
    rpm -qi unzip
    [ $? != 0 ] && yum install -y unzip 
    wget $ip/master.zip && unzip master.zip &&  cd trash-cli-master/  && python setup.py install # &> /dev/null
    if [ $? = 0 ];then
        echoGreen "编译安装成功，即将配置相应文件"
        [ ! -d /root/.local/share/Trash/files ] && mkdir -p /root/.local/share/Trash/files
    #yum install -y python-setuptools.noarch &> /dev/null && easy_install trash-cli &> /dev/null && sleep 3
        echo "alias rm='trash-put'" >> /etc/bashrc && source /etc/bashrc
        /usr/local/bin/trash --version &> /dev/null && echoGreen "/usr/local/bin/trash回收站已完成安装，可尽情享用……" || echoYellow "可能安装有问题,请检查，python2与python3安装的位置不一样"
        
       sleep 10
       echoYellow "python2与python3安装的路径不一样"
       /usr/bin/trash --version &> /dev/null && echoGreen "安装在/usr/bin/trash,回收站已完成安装，可尽情享用……" || echoYellow "可能安装有问题,请检查，python2与python3安装的位置不一样"
       source /etc/bashrc
       echoYellow "确保加载环境变量成功，请手动加载下source /etc/bashrc"
       sleep 6
       which trash
       if [ $? = 0 ];then
           echoRed "trash已经安装成功，即将安装autotrash"
    #autotrash
           /usr/bin/autotrash -V &> /dev/null && echoRed "检测到系统中有autotrash命令，故而退出！" && rm -rf $dir && exit 8
           #需要epel源
    #wget $ip/pack/autotrash.tar.gz && tar xf autotrash.tar.gz && cd autotrash && python setup.py instal 
           yum -y install autotrash
           /usr/bin/autotrash -V &> /dev/null && echoRed "autotrash安装失败，故而退出！" && rm -rf $dir && exit 9
           [ ! -d /root/.local/share/Trash/info ] && mkdir -p /root/.local/share/Trash/info
           which autotrash
           if [ $? = 0 ];then 
               echo "#add clean tool" >> /var/spool/cron/root
               echo "@daily /usr/bin/autotrash -d 7" >> /var/spool/cron/root
    #       echo "#add clean tool" >> /var/spool/cron/aladin
    #       echo "@daily /usr/bin/autotrash -d 7" >> /var/spool/cron/aladin
               /usr/bin/autotrash -h &> /dev/null && echoGreen "自动删除回收站七天前的内容功能已配置完成，可尽情享用！" || echoYellow "可能安装有问题，请检查！"
               pwd
               cd
               rm -rf $dir
               source /etc/bashrc && source /etc/bashrc
           else
               echoRed "未找到autotrash二进制路径,即将退出，请检查"
               cd 
               rm -rf $dir
               exit 28
           fi
       else
            echoYellow "未找到trash二进制路径，停止安装autotrash，即将退出，请检查"
            cd 
            rm -rf $dir && exit 21
       fi       
    else
        echoRed "trash编译安装失败，即将退出，请检查"
        cd 
        rm -rf $dir && exit 12
    fi
}
